$(document).ready(function(){
	getProvinceList();
});
//验证提交表单
function submitForm() {
	var kedaoForm = $(".kedaoForm").Validform({
		tiptype: 3,
		beforeSubmit:function(curform){
			//在验证成功后，表单提交前执行的函数，curform参数是当前表单对象。
			//这里明确return false的话表单将不会提交;
			$("#password").val($.md5($("#password").val()));	
			$("#tpassword").val($.md5($("#tpassword").val()));	
		}
	});
	kedaoForm.check();
	kedaoForm.submitForm(false);
}

function getProvinceList(){
	$.ajax({
   		async:false,
		url:'/admin/org!getProvinceList.action',
		type:'POST',
		dataType:'json',
		cache: false,
		success:function(data){
			Interceptor(data);
			var resultContent='';
			$(data).each(function(i) {
				resultContent+='<option value="'+data[i].code+'">'+data[i].name+'</option>';
			});
			$("#province").html(resultContent);
			
			findUser();
		},
		error:function(){
			alert("通信失败！");
		}
	});
}

function findUser(ids) {
	$.ajax({
		url : "/admin/user!findUserEdit.action",
		type : "post",
		dataType : "json",
		beforeSend : parent.msgLoading,
		complete : parent.successLoading,
		success : function(data){
			Interceptor(data);
			var sjreson="";
			var baocunIdStr="";
			
			if(data!=null){
				
				var dataUser=data[0];
				if(dataUser.reason!=""){
					sjreson=dataUser.reason;
				}
				var dataObj=dataUser.organization;
				$("#id").val(dataUser.id);
				$("#username").val(dataUser.username);
				$("#truename").val(dataUser.name);
				$("#name").val(dataObj.name);
				$("#organType").val(dataObj.organType);
				$("#organLevel").val(dataObj.organLevel);
				$("#organCode").val(dataObj.organCode);
				$("#address").val(dataObj.address);
				$("#postCode").val(dataObj.postCode);
				$("#contactUser").val(dataObj.contactUser);
				$("#contactPhone").val(dataObj.contactPhone);
				$("#contactMobile").val(dataObj.contactMobile);
				$("#contactEmail").val(dataObj.contactEmail);
				$("#province").val(dataObj.province.code);
				$("#responsiblePerson").val(dataObj.responsiblePerson);
			}
			
			if(sjreson!=""){
				$("#shenheId").show();
				$("#reasonId").show();
				$("#sjreson").html(sjreson);
			}else{
				$("#shenheId").hide();
				$("#reasonId").hide();
				$("#sjreson").html("");
			}
		},
		error : function() {
			alert("通信失败!");
		}
	});
}

function saveReason() {
	
	var reasonStr=$("#reason").html();
	if(""!=reasonStr){
		$.ajax({
		async:false,
		url:'/admin/user!saveUserReason.action?reason='+encodeURI(reasonStr),
		type:'POST',
		data: {
			"id":id
		},
		dataType:'Text',
		cache: false,
		success:function(data){
			Interceptor(data);
			if(data!=null){
				alert("保存成功");
				location.href='user_audit.jsp';
			}
		},
		error:function(){
			//nexts(tag);
		}
	});
	}else{
		alert("原因不能为空!");
	}
}